USE [dbdata]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_account_categ_id]') AND parent_object_id = OBJECT_ID(N'[dbo].[accounts]'))
ALTER TABLE [dbo].[accounts] DROP CONSTRAINT [fk_account_categ_id]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_account_user_id]') AND parent_object_id = OBJECT_ID(N'[dbo].[accounts]'))
ALTER TABLE [dbo].[accounts] DROP CONSTRAINT [fk_account_user_id]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF__accounts__summar__2F10007B]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[accounts] DROP CONSTRAINT [DF__accounts__summar__2F10007B]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF__accounts__dt__300424B4]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[accounts] DROP CONSTRAINT [DF__accounts__dt__300424B4]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF__accounts__enable__30F848ED]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[accounts] DROP CONSTRAINT [DF__accounts__enable__30F848ED]
END

GO

USE [dbdata]
GO

/****** Object:  Table [dbo].[accounts]    Script Date: 04/25/2012 11:59:05 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[accounts]') AND type in (N'U'))
DROP TABLE [dbo].[accounts]
GO

USE [dbdata]
GO

/****** Object:  Table [dbo].[accounts]    Script Date: 04/25/2012 11:59:05 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[accounts](
	[id] [bigint] IDENTITY(1,1) NOT NULL,
	[uid] [int] NOT NULL,
	[categ_id] [int] NOT NULL,
	[summary] [money] NOT NULL,
	[dt] [smalldatetime] NOT NULL,
	[dt_last] [smalldatetime] NULL,
	[enabled] [bit] NOT NULL,
	[OwnerAcc_id] [int] NULL,
PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[accounts]  WITH CHECK ADD  CONSTRAINT [fk_account_categ_id] FOREIGN KEY([categ_id])
REFERENCES [dbo].[account_categs] ([id])
GO

ALTER TABLE [dbo].[accounts] CHECK CONSTRAINT [fk_account_categ_id]
GO

ALTER TABLE [dbo].[accounts]  WITH CHECK ADD  CONSTRAINT [fk_account_user_id] FOREIGN KEY([uid])
REFERENCES [dbo].[users] ([id])
GO

ALTER TABLE [dbo].[accounts] CHECK CONSTRAINT [fk_account_user_id]
GO

ALTER TABLE [dbo].[accounts] ADD  DEFAULT ((0)) FOR [summary]
GO

ALTER TABLE [dbo].[accounts] ADD  DEFAULT (getdate()) FOR [dt]
GO

ALTER TABLE [dbo].[accounts] ADD  DEFAULT ((1)) FOR [enabled]
GO

